<template>
  <div>
    <div class="goods-list">
      <router-link tag="div" :to="'/home/goodsinfo/'+item.id" class="goods-item" v-for="item in goodlist" :key="item.id">
        <img :src="item.img_url" alt="" />
        <h1 class="title">{{ item.title }}</h1>
        <div class="info">
          <p class="price">
            <span class="new">{{ item.sell_price }} </span>
            <span class="old">{{ item.market_price }} </span>
          </p>
          <p class="sell">
            <span class="hot">热卖中</span>
            <span class="sold">已售：{{ item.stock_quantity }} </span>
          </p>
        </div>
      </router-link>
    </div>

    <mt-button class="button" type='danger' size='large' @click="getmore">加载更多</mt-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      page: 1,
      goodlist: [],
    };
  },
  methods: {
    async getgoodslistbypage() {
      const { data } = await this.$http.get(
        "/api/getgoods?pageindex=" + this.page
      );
      console.log(data.message);
        this.goodlist = this.goodlist.concat(data.message);
       
    },
    getmore(){
        this.page++
        this.getgoodslistbypage()
    }
  },
  created() {
    this.getgoodslistbypage();
  },
};
</script>

<style lang="scss" scoped>
.goods-list {
  padding: 5px;
  padding-top: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goods-item {
    .new {
      font-weight: bold;
      color: red;
      font-size: 15px;
      margin-right: 20px;
      margin-left: 10px;
    }
    .old {
      text-decoration: line-through;
    }
    padding: 2px;
    border: 1px solid #ccc;
    width: 49%;
    margin-top: 7px;
    box-shadow: 0 0 7px #ccc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .title {
      font-size: 15px;
    }
    img {
      width: 100%;
      height: 170px;
    }
    .info {
      overflow: hidden;
      background-color: #ccc;
      .hot {
        margin-right: 45px;
      }
    }
    .price {
      padding-left: 7px;
      padding-right: 7px;
     
    }
  }
}

p {
  margin-bottom: 0;
}

.button{
    width: 95%;
    margin:10px;
}
</style>
